package com.fcl.oschina.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;

import com.fcl.mylibrary.recyclerviewhelper.BaseAdapter;
import com.fcl.mylibrary.recyclerviewhelper.BaseHolder;
import com.fcl.mylibrary.util.StringUtil;
import com.fcl.oschina.R;
import com.fcl.oschina.entity.TweetEntity;

import java.util.List;

/**
 * Created by Administrator on 2017/3/20.
 */

public class TweetAdapter extends BaseAdapter<TweetEntity> {
    public TweetAdapter(Context context, int layoutId, List<TweetEntity> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void bindHolder(BaseHolder baseHolder, TweetEntity data) {
        super.bindHolder(baseHolder, data);
        baseHolder.setText(R.id.user_name, data.getAuthor().getName());
        baseHolder.setText(R.id.content, Html.fromHtml(data.getContent()).toString());
        baseHolder.setImage(R.id.user_avtar, data.getAuthor().getPortrait());
        baseHolder.setText(R.id.date, StringUtil.formatSomeAgo(data.getPubDate()));
        baseHolder.setText(R.id.comment, data.getCommentCount()+"");
        if (true && data.getImages() != null ) {
            RecyclerView recyclerView = (RecyclerView) baseHolder.getView(R.id.image_recycler);
            ImageAdapter imageAdapter = new ImageAdapter(mContext, R.layout.item_image, data.getImages());
            imageAdapter.setShowFooter(false);
            recyclerView.setAdapter(imageAdapter);
            recyclerView.setLayoutManager(new GridLayoutManager(mContext,3));
        }

    }
}
